<?php
require_once("../includes/Database.class.php");
require_once("../includes/Resource.class.php");
require_once("../includes/Equipment.class.php");
require_once("../includes/Room.class.php");
require_once("../includes/Equipment_type.class.php");
require_once("../includes/Room_type.class.php");


$name = $_POST["name"];
$resource_type = $_POST["resource_type"];
$description = $_POST["description"];

if ( $resource_type == "R" )
    {
     $room_type = $_POST["room_type"];
	 $capacity = $_POST["capacity"];
	 $position = $_POST["position"];
    }
else if($resource_type == "E")  
    {
     $equipment_type = $_POST["equipment_type"];
	 $model = $_POST["model"];
	 $state = $_POST["state"];
	 $date = $_POST["date"];
    }  


$resource = new Resource();
$resource->set_name($name);
$resource->set_description($description) ;
$resource->set_resource_type($resource_type) ;
$resource->create();
global $database;
$resource_ID = $database->insert_id();


if($resource_type == "R")
{
$room = new Room();
$room->set_resource_id($resource_ID);
$room->set_capacity($capacity);
$room->set_position($position);
$room->set_room_type($room_type);
$room->create();
}

else if($resource_type == "E")
{
$equipment = new Equipment();
$equipment->set_resource_id($resource_ID);
$equipment->set_date($date);
$equipment->set_model($model);
$equipment->set_state($state);
$equipment->set_equipment_type($equipment_type);
$equipment->create();
}


header("Location: admin_home.php");

?>